﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

using ProfileManager.Controls;
using ProfileManager.DataAccess;

namespace ProfileManager.Forms
{
    public partial class MainForm : MasterForm
    {
        public MainForm()
        {
            InitializeComponent();

            ShowCustomLeftButton = false;
            ShowCustomRightButton = false;
        }

        private void FillServiceTypeList()
        {
            pServiceTypeList.Controls.Clear();

            List<ServiceType> serviceTypes = ServiceType.Select();
            if (serviceTypes != null)
            {
                TableLayoutPanel tlpServiceTypes = new TableLayoutPanel
                {
                    ColumnCount = 1,
                    RowCount = serviceTypes.Count,
                    Dock = DockStyle.Fill
                };

                for (int i = 0; i < serviceTypes.Count; i++)
                {
                    tlpServiceTypes.RowStyles.Add(new RowStyle(SizeType.Absolute, 24F));

                    ServiceTypeBox serviceTypeBox = new ServiceTypeBox(serviceTypes[i]);
                    tlpServiceTypes.Controls.Add(serviceTypeBox, 0, i);
                }
                pServiceTypeList.Controls.Add(tlpServiceTypes);
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            FillServiceTypeList();
        }

        private void tsbAddServiceType_Click(object sender, EventArgs e)
        {
            AddServiceTypeForm addServiceTypeForm = new AddServiceTypeForm();
            if (addServiceTypeForm.ShowDialog() == DialogResult.OK)
            {
                FillServiceTypeList();
            }
        }

        private void tsbAddServiceInfo_Click(object sender, EventArgs e)
        {
            AddServiceInfoForm addServiceInfoForm = new AddServiceInfoForm();
            addServiceInfoForm.ShowDialog();
        }

        private void tsbAddAccountInfo_Click(object sender, EventArgs e)
        {
            AddServiceAccountForm addServiceAccountForm = new AddServiceAccountForm();
            addServiceAccountForm.ShowDialog();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            List<ServiceType> serviceTypes = ServiceType.Select();
            if (serviceTypes != null)
            {
                List<ServiceTypeBox> sb = new List<ServiceTypeBox>();

                for (int i = 0; i < serviceTypes.Count; i++)
                {
                    

                    ServiceTypeBox serviceTypeBox = new ServiceTypeBox(serviceTypes[i]);
                    sb.Add(serviceTypeBox);
                }

                serviceAccountItemList1.ItemCount = sb.Count;
                serviceAccountItemList1.Init<ServiceTypeBox, ServiceTypeBoxCreator>();
                serviceAccountItemList1.AddRange(sb);
            }
        }
    }
}
